package com.jiangore.config.datasource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

/**
 * @Todo
 * @Author jiangtao
 * @CreateBy 2020-03-09 1:45 PM
 * @UpdateBy jiangtao
 * @Version v1.0
 */
@Configuration
public class DataSourceTwoConfig {

    // 从数据库
    @Bean(name = "twoDataSource")
    @Qualifier("twoDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.two")
    public DataSource twoDataSource (){
        return DataSourceBuilder.create().build() ;
    }

    @Bean(name = "twoJdbcTemplate")
    public JdbcTemplate twoJdbcTemplate (@Qualifier("twoDataSource") DataSource dataSource){
        return new JdbcTemplate(dataSource);
    }
}
